import { User } from "src/class/user";

class UserManager {
    private users: User[] = [];

    private kUidStart: number = 0;

    public createNewUid()
    {
        return this.kUidStart + this.users.length + 1;
    }

    public getUserByPsw(userName: string, psw: string)
    {
        for (let key in this.users) {
            let user = this.users[key];
            if (user.userName == userName && user.psw == psw) {
                return user;
            }
        }

        return null;
    }

    public getUserByUid(uid: number)
    {
        for (let key in this.users) {
            let user = this.users[key];
            if (user.uid == uid) {
                return user;
            }
        }

        return null;
    }

    public registerUser(user: User)
    {
        this.users.push(user);
    }
}

export let userManager = new UserManager();